package com.partner.boot.common.enums;

import lombok.Getter;

/**
 *  规范前端传过来的发送邮箱验证码的类型
 */
@Getter
public enum EmailCodeEnum {
    LOGIN("LOGIN","login:"), // 登录
    REGISTER("REGISTER","register:"), // 注册
    RESET_PASSWORD("RESET_PASSWORD","resetPassword:"), // 重置密码
    CHANGE_PASSWORD("CHANGE_PASSWORD","changePassword:"), // 修改密码
    UNKNOWN("",""); // 找不到匹配的类型

    private final String type;
    private final String value;

    /**
     * 根据前端传过来的验证类型获取枚举的value值
     * @param type
     * @return
     */
    public static String getValue(String type) {
        EmailCodeEnum[] values = values();
        for (EmailCodeEnum codeEnum : values) {
            if (type.equals(codeEnum.type)) {
                return codeEnum.value;
            }
        }
        return "";
    }

    /**
     * 根据前端传过来的验证类型获取枚举
     * @param type
     * @return
     */
    public static EmailCodeEnum getEnum(String type) {
        EmailCodeEnum[] values = values();
        for (EmailCodeEnum codeEnum : values) {
            if (type.equals(codeEnum.type)) {
                return codeEnum;
            }
        }
        return UNKNOWN;
    }

    EmailCodeEnum(String type, String value) {
        this.type = type;
        this.value = value;
    }
}
